package com.cafe.pro.controller;

import com.cafe.pro.dto.UserSaveDto;
import com.cafe.pro.dto.UserSearchRequest;
import com.cafe.pro.service.UserService;
import com.cafe.pro.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public ResponseEntity<UserVo> getUser(@PathVariable Integer id) {
        UserVo user = userService.getUserById(id);
        return ResponseEntity.ok(user);
    }

    @GetMapping
    public List<UserVo> list(UserSearchRequest request) throws Exception {
        return userService.listUsers(request);
    }

    @PostMapping
    public String add(@RequestBody UserSaveDto user) {
        return userService.addUser(user) ? "Success" : "Failed";
    }
}
